/*
类：轨迹对象
属性：
    fileName: 名称
    coordsList：坐标序列
    color：后续渲染的图层颜色
方法：
    getRandomColor：随机生成颜色
        output：生成的颜色rgb
*/
class TraObject {
  fileName;
  coordsList;
  color;
  static extractCoordsSeq(message) {
    const regex = /\[(\[\d+(\.\d+)?,\d+(\.\d+)?\],){1,}(\[\d+(\.\d+)?,\d+(\.\d+)?\])\]/g;
    const matches = message.match(regex);
    let extractedArrays = null;
    if (matches) {
      try {
        extractedArrays = matches.map((match) => JSON.parse(match)); // 匹配到的内容数组
      } catch (error) {
        console.log(error);
        return null;
      }
      return JSON.stringify(extractedArrays); //返回字符串
    }
    return extractedArrays;
  }
  static getRandomColor() {
    //随机颜色生成
    const red = Math.floor(Math.random() * 256);
    const green = Math.floor(Math.random() * 256);
    const blue = Math.floor(Math.random() * 256);
    return `rgb(${red}, ${green}, ${blue})`;
  }
  constructor(fileName, coordsList, color = TraObject.getRandomColor()) {
    this.fileName = fileName;
    this.coordsList = coordsList;
    this.color = color;
  }
}

export { TraObject };
